package com.lz.commonlibrary.utils;

import android.content.Context;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeTools {
	/**
	 * 求两个日期之间的   相差天数
	 * @param
	 * @param
	 * @return
	 */
	public static long  getFromCurrentDate2TimeDays(String time){
		long quot = 0;
		  SimpleDateFormat ft = new SimpleDateFormat("yyyy/MM/dd");
		  try {
		   Date date1 = ft.parse( time );
		   Date date2 = new Date();
		   quot =   date2.getTime() - date1.getTime();
		   quot = quot / 1000 / 60 / 60 / 24;
		  } catch (ParseException e) {
		   e.printStackTrace();
		  }
		  return quot;
	}
	
	public static long  getFromCurrentDate2TimeDays(Date date1){
		long quot = 0;
		   Date date2 = new Date();
		   quot =   date2.getTime() - date1.getTime(); 
		   
		   quot = Math.abs(quot);
		   quot = quot / 1000 / 60 / 60 / 24;
		   
		   
		  return quot;
	}
	
	public static long getQuot(String time1, String time2){
		  long quot = 0;
		  SimpleDateFormat ft = new SimpleDateFormat("yyyy/MM/dd");
		  try {
		   Date date1 = ft.parse( time1 );
		   Date date2 = ft.parse( time2 );
		   quot = date1.getTime() - date2.getTime();
		   quot = quot / 1000 / 60 / 60 / 24;
		  } catch (ParseException e) {
		   e.printStackTrace();
		  }
		  return quot;
		 }

    /**
     * 获取系统当前时间
     * @return
     */
    public static String getSystemDate(){
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return ft.format(new Date());
    }
    
    /**
     * 
     * @ 功能  获取当前day
     * @return
     * @ 作者  2014-8-15  / 黄赛赛
     */
    public static String getCurDayDate(){
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        return ft.format(new Date());
    }
    /**
     * 获取系统当前时间
     * @return
     */
    public static long getSystemSeconds(){
    	Date d = new Date();
    	return d.getTime();
    }
    
    public static String getFormatDate(Date date){
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return ft.format(date);
    }
    public static String getFormatDateDay(Date date){
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        return ft.format(date);
    }
    
    public static String getFormatDateDayCN(Date date){
        SimpleDateFormat ft = new SimpleDateFormat("yyyy年MM月dd日");
        return ft.format(date);
    }
    public static String getFormatDateMinute(Date date){
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return ft.format(date);
    }
    public static Date getDate(String time){
    	Date date = null;
    	SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
			date = ft.parse( time );
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return date;
    }

	public static String getHourMinute(Date date){
		SimpleDateFormat ft = new SimpleDateFormat("HH:mm");
		return ft.format(date);
	}
	public static String getMonthDay(Date date){
		SimpleDateFormat ft = new SimpleDateFormat("MM-dd");
		return ft.format(date);
	}
	public static String getYearMonthDay(Date date){
		SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
		return ft.format(date);
	}



	public  static boolean is24HourFormat(Context context){
		return  android.text.format.DateFormat.is24HourFormat(context);
	}


//	public  static Date getCurTime24Hour(Context context){
//		if (is24HourFormat(context)){
//			return  new Date();
//		}else {
//			final Calendar mCalendar = Calendar.getInstance();
//			int apm = mCalendar.get(Calendar.AM_PM);
//
//			//apm=0 表示上午，apm=1表示下午。
//			if (apm == 1){
//				long curMinSec = mCalendar.getTime().getTime();
//				curMinSec += 12*60*60*1000;
//				LogUtils.e(TimeTools.getFormatDateMinute(new Date(curMinSec)));
//				return new Date (curMinSec);
//			}else {
//				return  mCalendar.getTime();
//			}
//		}
//
//	}
}
